package com.Tank.draw;

public class Shot implements Runnable {
    int x;//子弹x坐标
    int y;//子弹y坐标
    int direct = 0;//子弹初始点
    int speed = 2;//子弹速度
    boolean isLive = true;

    public Shot(int x, int y, int direct) {
        this.x = x;
        this.y = y;
        this.direct = direct;

    }

    @Override
    public void run() {
        while (true) {
            try {
                Thread.sleep(50);//子弹休眠
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            //根据方向改变坐标
            switch (direct) {
                case 0://上
                    y -= speed;
                    break;
                case 1://右
                    x += speed;
                    break;
                case 2://下
                    y += speed;
                    break;
                case 3://左
                    x -= speed;
                    break;
            }
            int i=0;
            //System.out.println(x + "," + y +(i++));
            if (!(x <= 1000 && x >= 0 && y >= 0 && y <= 750 && isLive)) {
                isLive = false;
                i++;
                System.out.println("over shot" + i);
                break;
            }
        }
    }
}